﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports System
Imports System.Runtime.Serialization
Imports System.Xml.Linq
Imports System.Xml.Serialization
Imports System.Xml

Namespace CMISObjects
   <XmlRoot("allowableActions", Namespace:=CmisNamespaceConstants.Cmis)>
   Public Class AllowableActions
      Implements IXmlSerializable

#Region "Navigation Services"

      Public Property CanGetDescendants() As Boolean

      Public Property CanGetFolderTree() As Boolean

      Public Property CanGetChildren() As Boolean

      Public Property CanGetFolderParent() As Boolean

      Public Property CanGetObjectParents() As Boolean

#End Region

#Region "Object Services"

      Public Property CanCreateDocument() As Boolean

      Public Property CanCreateFolder() As Boolean

      Public Property CanCreateRelationship() As Boolean

      Public Property CanGetProperties() As Boolean

      Public Property CanGetRenditions() As Boolean

      Public Property CanGetContentStream() As Boolean

      Public Property CanUpdateProperties() As Boolean

      Public Property CanMoveObject() As Boolean

      Public Property CanDeleteObject() As Boolean

      Public Property CanSetContentStream() As Boolean

      Public Property CanDeleteContentStream() As Boolean

      Public Property CanDeleteTree() As Boolean

#End Region

#Region "Multi-Filing Services"

      Public Property CanAddObjectToFolder() As Boolean

      Public Property CanRemoveObjectFromFolder() As Boolean


#End Region

#Region "Versioning Services"


      Public Property CanCheckOut() As Boolean

      Public Property CanCancelCheckOut() As Boolean

      Public Property CanCheckIn() As Boolean

      Public Property CanGetAllVersions() As Boolean


#End Region

#Region "Relationship Services"

      Public Property CanGetObjectRelationships() As Boolean


#End Region

#Region "Policy Services"

      Public Property CanApplyPolicy() As Boolean

      Public Property CanRemovePolicy() As Boolean

      Public Property CanGetAppliedPolicies() As Boolean

#End Region

#Region "ACL Services"

      Public Property CanGetACL() As Boolean

      Public Property CanApplyACL() As Boolean

#End Region

      Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
         Return Nothing
      End Function

      Public Sub ReadXml(reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
         Dim doc As New XmlDocument()
         doc.Load(reader)
         Dim principalIds As New List(Of String)
         Dim permissions As New List(Of String)
         Dim direct As Boolean = False

         Dim node As XmlNode = Common.GetItemCaseInsensitiveFromXML(doc, "allowableactions")
         For Each child As XmlNode In node.ChildNodes
            Dim lname As String = Common.GetNodeNameWithoutPrefix(child).ToLowerInvariant
            If lname.Equals("canaddobjecttofolder") Then
               Me.CanAddObjectToFolder = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canapplyacl") Then
               Me.CanApplyACL = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canapplypolicy") Then
               Me.CanApplyPolicy = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancancelcheckout") Then
               Me.CanCancelCheckOut = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancheckin") Then
               Me.CanCheckIn = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancheckout") Then
               Me.CanCheckOut = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancreatedocument") Then
               Me.CanCreateDocument = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancreatefolder") Then
               Me.CanCreateFolder = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cancreaterelationship") Then
               Me.CanCreateRelationship = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("candeletecontentstream") Then
               Me.CanDeleteContentStream = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("candeleteobject") Then
               Me.CanDeleteObject = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("candeletetree") Then
               Me.CanDeleteTree = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetacl") Then
               Me.CanGetACL = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetallversions") Then
               Me.CanGetAllVersions = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetappliedpolicies") Then
               Me.CanGetAppliedPolicies = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetchildren") Then
               Me.CanGetChildren = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetcontentstream") Then
               Me.CanGetContentStream = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetdescendants") Then
               Me.CanGetDescendants = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetfolderparent") Then
               Me.CanGetFolderParent = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetfoldertree") Then
               Me.CanGetFolderTree = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetobjectparents") Then
               Me.CanGetObjectParents = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetobjectrelationships") Then
               Me.CanGetObjectRelationships = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetproperties") Then
               Me.CanGetProperties = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cangetrenditions") Then
               Me.CanGetRenditions = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canmoveobject") Then
               Me.CanMoveObject = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canremoveobjectfromfolder") Then
               Me.CanRemoveObjectFromFolder = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canremovepolicy") Then
               Me.CanRemovePolicy = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("cansetcontentstream") Then
               Me.CanSetContentStream = Boolean.Parse(child.InnerText)
            ElseIf lname.Equals("canupdateproperties") Then
               Me.CanUpdateProperties = Boolean.Parse(child.InnerText)
            End If
         Next

      End Sub

      Public Sub WriteXml(writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
         Dim nsCore As String = CmisNamespaceConstants.Cmis
         writer.WriteElementString("canDeleteObject", nsCore, CanDeleteObject.ToString.ToLowerInvariant)
         writer.WriteElementString("canUpdateProperties", nsCore, CanUpdateProperties.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetFolderTree", nsCore, CanGetFolderTree.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetProperties", nsCore, CanGetProperties.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetObjectRelationships", nsCore, CanGetObjectRelationships.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetObjectParents", nsCore, CanGetObjectParents.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetFolderParent", nsCore, CanGetFolderParent.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetDescendants", nsCore, CanGetDescendants.ToString.ToLowerInvariant)
         writer.WriteElementString("canMoveObject", nsCore, CanMoveObject.ToString.ToLowerInvariant)
         writer.WriteElementString("canDeleteContentStream", nsCore, CanDeleteContentStream.ToString.ToLowerInvariant)
         writer.WriteElementString("canCheckOut", nsCore, CanCheckOut.ToString.ToLowerInvariant)
         writer.WriteElementString("canCancelCheckOut", nsCore, CanCancelCheckOut.ToString.ToLowerInvariant)
         writer.WriteElementString("canCheckIn", nsCore, CanCheckIn.ToString.ToLowerInvariant)
         writer.WriteElementString("canSetContentStream", nsCore, CanSetContentStream.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetAllVersions", nsCore, CanGetAllVersions.ToString.ToLowerInvariant)
         writer.WriteElementString("canAddObjectToFolder", nsCore, CanAddObjectToFolder.ToString.ToLowerInvariant)
         writer.WriteElementString("canRemoveObjectFromFolder", nsCore, CanRemoveObjectFromFolder.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetContentStream", nsCore, CanGetContentStream.ToString.ToLowerInvariant)
         writer.WriteElementString("canApplyPolicy", nsCore, CanApplyPolicy.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetAppliedPolicies", nsCore, CanGetAppliedPolicies.ToString.ToLowerInvariant)
         writer.WriteElementString("canRemovePolicy", nsCore, CanRemovePolicy.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetChildren", nsCore, CanGetChildren.ToString.ToLowerInvariant)
         writer.WriteElementString("canCreateDocument", nsCore, CanCreateDocument.ToString.ToLowerInvariant)
         writer.WriteElementString("canCreateFolder", nsCore, CanCreateFolder.ToString.ToLowerInvariant)
         writer.WriteElementString("canCreateRelationship", nsCore, CanCreateRelationship.ToString.ToLowerInvariant)
         writer.WriteElementString("canDeleteTree", nsCore, CanDeleteTree.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetRenditions", nsCore, CanGetRenditions.ToString.ToLowerInvariant)
         writer.WriteElementString("canGetACL", nsCore, CanGetACL.ToString.ToLowerInvariant)
         writer.WriteElementString("canApplyACL", nsCore, CanApplyACL.ToString.ToLowerInvariant)
      End Sub
   End Class
End Namespace